import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Pokers {
    public static final String[] SUIT = {"♥","♠","♣","♦"}; //4种花色

    public static List<Poker> buyPoker(){
        List<Poker> pokerList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            List<Poker> pokerlist = new ArrayList<>();
            for (int j = 1; j <= 13; j++) {
                String suit = SUIT[i];
                Poker poker = new Poker(suit,j);
                pokerList.add(poker);
                pokerlist.add(poker);
            }
            //System.out.println(pokerlist);
        }
        return pokerList;
    }

    public static void Swap(List<Poker> pokerList,int i,int j){
        Poker temp = pokerList.get(i);
        pokerList.set(i,pokerList.get(j));
        pokerList.set(j,temp);

    }

    public static void shuffle(List<Poker> pokerList){
        Random random = new Random();
        for (int i = pokerList.size()-1; i > 0; i--) {
            int index = random.nextInt(i);
            Swap(pokerList,index,i);
        }
    }

    public static List<List<Poker>> Catch (List<Poker> pokerList){
        //揭牌：3个人 每个人 轮流抓5张牌
        //1、如何描述3个人？
        List<Poker> person1 = new ArrayList<>();
        List<Poker> person2 = new ArrayList<>();
        List<Poker> person3 = new ArrayList<>();
        //2、如何区分 往哪个人手里放牌？
        List<List<Poker>> hand = new ArrayList<>();
        hand.add(person1);
        hand.add(person2);
        hand.add(person3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                //确定是谁的手
                List<Poker> handtemp = hand.get(j);
                //每次都是0下标
                handtemp.add(pokerList.remove(0));
            }
        }
        return hand;
    }

    public static void display (List<List<Poker>> hand){
        for (int i = 0; i < hand.size(); i++) {
            System.out.println("第"+(i+1)+"个人的牌是："+hand.get(i));
        }
    }

    public static void main(String[] args) {
        //准备扑克牌
        List<Poker> PokerList = buyPoker();
        System.out.println("洗牌前："+PokerList);
        //实现洗牌
        shuffle(PokerList);
        System.out.println("洗牌后："+PokerList);
        //用户抓牌
        List<List<Poker>> hand = Catch(PokerList);
        //打印抓牌结果
        display (hand);
//        //打印剩余的牌
        System.out.println("剩余的牌："+ PokerList);
    }
}
